package com.yuyu.exception;

import com.yuyu.exception.EmployeeException.AddEmployeeException;
import com.yuyu.exception.EmployeeException.DeleteEmployeeException;
import com.yuyu.exception.EmployeeException.EditEmployeeException;
import com.yuyu.exception.EmployeeException.EmployeeNotExsitException;
import com.yuyu.uitlbean.MessageCode;
import com.yuyu.uitlbean.ResultObj;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class CustomExceptionHandler {

    //捕获员工不存在异常
    @ExceptionHandler(EmployeeNotExsitException.class)
    public ResultObj handleEmployeeNotExsitException(Exception e){
        return new ResultObj(MessageCode.EMPLOYEE_NOT_EXSIT);
    }

    //捕获编辑员工失败异常
    @ExceptionHandler(EditEmployeeException.class)
    public ResultObj handleEditEmployeeException(Exception e){
        return new ResultObj(e.getMessage(),MessageCode.FAILED.getCode());
    }

    //捕获删除员工失败异常
    @ExceptionHandler(DeleteEmployeeException.class)
    public ResultObj handleDeleteEmployeeException(Exception e){
        return new ResultObj(e.getMessage(),MessageCode.FAILED.getCode());
    }

    //捕获添加员工失败异常
    @ExceptionHandler(AddEmployeeException.class)
    public ResultObj handleAddEmployeeException(Exception e){
        return new ResultObj(e.getMessage(),MessageCode.FAILED.getCode());
    }

    //捕获导出员工excel异常
    @ExceptionHandler(ExportExcelException.class)
    public ResultObj handleExportExcelException(Exception e){
        return new ResultObj(e.getMessage(),MessageCode.FAILED.getCode());
    }

    //捕获导入员工excel异常
    @ExceptionHandler(ImportExcelException.class)
    public ResultObj handleImportExcelException(Exception e){
        return new ResultObj(e.getMessage(),MessageCode.FAILED.getCode());
    }
}
